package controller;

//TODO describe this class

import gui.Display;
import gui.SettingsDisplay;

import java.rmi.RemoteException;

import model.user.User;

public class SettingsController extends Controller {
	//TODO describe the constructors and initializeDisplay
	public SettingsController(Display display) {
		SettingsDisplay settingsDisplay = new SettingsDisplay(this, display);
		setDisplay(settingsDisplay);
	}
	
	public SettingsController(Display display, boolean initializeDisplay) {
		if (initializeDisplay) {
			SettingsDisplay settingsDisplay = new SettingsDisplay(this, display);
			setDisplay(settingsDisplay);
		}
	}

	public void initializeDisplay(Display display) {
		SettingsDisplay settingsDisplay = new SettingsDisplay(this, display);
		setDisplay(settingsDisplay);
	}
	
	/**
	 * Display the lobby screen by giving control to the lobby controller
	 */
	public void returnToLobby() {
		Controller lobbyController = new LobbyController(display);
		this.giveControlTo(lobbyController);
	}
	
	/**
	 * Change the user's username to the one given as a parameter
	 * @param newUsername the new username to be set for the user
	 * @return true if the username has been changed, false otherwise
	 * @throws RemoteException
	 */
	public boolean setNewUsername(String newUsername) throws RemoteException {
		User temp = serverRemote.modifyUsername(user, newUsername);

		if (temp != null) {
			this.user = temp;
			return true;
		}
		else {
			return false;
		}
	}
	
	/**
	 * Change the user's password to the new one given as a parameter
	 * @param oldPass the user's old password
	 * @param newPass the new password to be modified
	 * @return true is the password was modified, false otherwise
	 * @throws RemoteException
	 */
	public boolean changePassword(String oldPass, String newPass) throws RemoteException {
		User temp = serverRemote.modifyPassword(user, oldPass, newPass);
		
		if (temp != null) {
			this.user = temp;
			return true;
		}
		else {
			return false;
		}	
	}
	
	/**
	 * Changed the users personal information to those in the parameters
	 * @param firstName String representing the user's first name
	 * @param lastName String representing the user's last name
	 * @param age String representing the user's age
	 * @param gender String representing the user's gender
	 * @param location String representing the user's location
	 * @return true if the settings were changes, false otherwise
	 * @throws RemoteException
	 */
	public boolean changePersonalInfo(String firstName, String lastName, String age, String gender, String location) throws RemoteException{		
		User temp = serverRemote.changePersonalInfo(user, firstName, lastName, age, gender, location); 
		
		if (temp != null) {
			this.user = temp;
			return true;
		}
		else {
			return false;
		}	
	}	
}
